package org.example.wx_springboot.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.common.Result;
import org.example.wx_springboot.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@CrossOrigin//这个注解是解决跨域错误的
public class UploadConttroller {
    /**
     *
     */
    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("文件上传，文件名{}",image.getOriginalFilename());//获取文件原始名字
//        调用阿里云工具类上传
        String url = aliOSSUtils.upload(image);
        log.info("文件上传完成，文件访问的url：{}",url);
        System.out.println(url);
        return Result.success(url);
    }
}
